#include "LogOpenFileDirHelper.h"
#include <QApplication>
#include <QFile>
#include <QFileInfo>
#include <QTextStream>

#include <QDir>

LogOpenFileDirHelper::LogOpenFileDirHelper(void)
{
}


LogOpenFileDirHelper::~LogOpenFileDirHelper(void)
{
}

QString LogOpenFileDirHelper::getOpenedFile( const QString& tag )
{

	QString configFile = qApp->applicationDirPath() + "/ "+ tag + ".txt"; 
	QString defaultDir = "";
	QFile file(configFile);
	if (file.open(QIODevice::ReadOnly |QIODevice::Text))
	{
		if(!file.atEnd())
		{
			defaultDir = file.readLine();
		}
		file.close();
	}

	return defaultDir;
}

void LogOpenFileDirHelper::saveOpenedFile( const QString& tag, const QString& filePath )
{
	QString configFile = qApp->applicationDirPath() + "/ "+ tag + ".txt"; 
	QFileInfo fileInfo(filePath);
	QFile file(configFile);
	if (file.open(QIODevice::WriteOnly |QIODevice::Text))			
	{
		QTextStream out(&file);
		out << fileInfo.absoluteDir().path();
	}
}
